package lab02.Test23;


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;

/**
 * Created by 123 on 2017/11/1.
 */
public class Test23 {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();//使用默认时区和语言环境获得一个日历。
        Calendar cal2 = Calendar.getInstance();
        //cal.add(Calendar.DAY_OF_MONTH, -1);//取当前日期的前一天.
        // cal.add(Calendar.DAY_OF_MONTH, +1);//取当前日期的后一天.

        Scanner sc = new Scanner(System.in);//从键盘输入日期

        int Year, Month, Day;

        System.out.println("生日年份:");
        Year = sc.nextInt();

        System.out.println("生日月份:");
        Month = sc.nextInt();

        System.out.println("生日号数:");
        Day = sc.nextInt();

        cal.set(Year, Month - 1, Day);//将输入的转换为日期型//为什么月份要减一？

        int birthweek = cal.get(Calendar.DAY_OF_WEEK);//获得星期几
        int birthday = cal.get(Calendar.DAY_OF_YEAR);//获得是一年中第多少天


        System.out.println("您的生日为星期" + (birthweek - 1));//因为从星期天开始，所以要减一

//通过格式化输出日期
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println("Today is:" + format.format(Calendar.getInstance().getTime()));


        int today = cal2.get(Calendar.DAY_OF_YEAR);

        if (birthday > today) {
            System.out.println("距离你的生日还有" + (birthday - today) + "天");
        } else if (birthday == today) {
            System.out.println("就是今天");
        } else {
            System.out.println("你的生日已经过了" + (today - birthday) + "天");
        }

    }
}